home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1996 / MacHack 1996.toast / Hacks / Hacks ’95 / Newt-A-Note & Suck-A-Note 1.0 / Newt-A-Note / LlamaTalk.h < prev    next >
Encoding:
Text File  |  1995-06-23  |  8.6 KB  |  215 lines  |  [TEXT/KAHL]

  1. //===========================================================================================
  2. //    LlamaTalk
  3. //
  4. //    Copyright © 1994 Apple Computer, Inc.
  5. //    All rights reserved.
  6. //
  7. //    Modification Status
  8. //    YY/MM/DD    Name            Comments
  9. //    94/07/07    Jim Schram        Released C header with Pascal 1.0a3 release
  10. //    94/03/17    Jim Schram        Initial Development
  11. //===========================================================================================
  12.  
  13. #ifndef __LLAMATALK_H__
  14. #define __LLAMATALK_H__
  15.  
  16. #include <Connections.h>
  17.  
  18. //----------------------------------------
  19. //    CODE RESOURCES
  20. //----------------------------------------
  21. #define cLTCompProcResType            'lama'
  22. #define    cLTCompProcResName_Listen    'LlamaTalkCPListen'
  23. #define    cLTCompProcResName_Open        'LlamaTalkCPOpen'
  24. #define    cLTCompProcResName_Close    'LlamaTalkCPClose'
  25. #define    cLTCompProcResName_Read        'LlamaTalkCPRead'
  26. #define    cLTCompProcResName_Write    'LlamaTalkCPWrite'
  27.  
  28. //----------------------------------------
  29. //    ERROR CODES
  30. //----------------------------------------
  31. #define    cLTSocketTableFull        -17001                    // Socket table full -- no free indexes -- can't open any more connections
  32. #define    cLTBadToolName            -17002                    // Illegal or bad Comm Toolbox tool-name encountered
  33. #define    cLTBadConfig            -17003                    // Bad socket configuration parameters
  34.  
  35. //----------------------------------------
  36. //    PACKET TYPES
  37. //----------------------------------------
  38. #define cLTPacketType_Simple    0                        // LlamaTalk packet type descriptor.  Currently only type 0 is implemented.
  39.  
  40. //----------------------------------------
  41. //    cLTBitsPhase... for INTERNAL USE ONLY
  42. //----------------------------------------
  43. #define    cLTBitsPhaseListen    0x80
  44. #define    cLTBitsPhaseOpen     0x40
  45. #define    cLTBitsPhaseClose     0x20
  46. #define    cLTBitsPhaseRead     0x10
  47. #define    cLTBitsPhaseWrite     0x08
  48.  
  49. #define    cLTBitsPhaseError     0x07
  50. #define    cLTBitsPhase6         0x06
  51. #define    cLTBitsPhase5         0x05
  52. #define    cLTBitsPhase4         0x04
  53. #define    cLTBitsPhase3         0x03
  54. #define    cLTBitsPhase2        0x02
  55. #define    cLTBitsPhase1        0x01
  56.  
  57. #define    cLTStateError        0x8000
  58. #define    cLTStateDispose        0x4000
  59. #define    cLTStateIdle        0x2000
  60. #define    cLTStateListen        0x1000
  61. #define    cLTStateOpen        0x0800
  62. #define    cLTStateClose        0x0400
  63. #define    cLTStateReadWrite    0x0300
  64.  
  65. #define    cLTListenPhase1        (cLTBitsPhaseListen + cLTBitsPhase1)
  66. #define    cLTListenPhase2        (cLTBitsPhaseListen + cLTBitsPhase2)
  67. #define    cLTListenPhase3        (cLTBitsPhaseListen + cLTBitsPhase3)
  68. #define    cLTListenPhase4        (cLTBitsPhaseListen + cLTBitsPhase4)
  69. #define    cLTListenPhaseError    (cLTBitsPhaseListen + cLTBitsPhaseError)
  70.  
  71. #define    cLTOpenPhase1        (cLTBitsPhaseOpen + cLTBitsPhase1)
  72. #define    cLTOpenPhase2        (cLTBitsPhaseOpen + cLTBitsPhase2)
  73. #define    cLTOpenPhase3        (cLTBitsPhaseOpen + cLTBitsPhase3)
  74. #define    cLTOpenPhaseError    (cLTBitsPhaseOpen + cLTBitsPhaseError)
  75.  
  76. #define    cLTClosePhase1        (cLTBitsPhaseClose + cLTBitsPhase1)
  77. #define    cLTClosePhase2        (cLTBitsPhaseClose + cLTBitsPhase2)
  78. #define    cLTClosePhase3        (cLTBitsPhaseClose + cLTBitsPhase3)
  79. #define    cLTClosePhase4        (cLTBitsPhaseClose + cLTBitsPhase4)
  80. #define    cLTClosePhaseError    (cLTBitsPhaseClose + cLTBitsPhaseError)
  81.  
  82. #define    cLTReadPhase1        (cLTBitsPhaseRead + cLTBitsPhase1)
  83. #define    cLTReadPhase2        (cLTBitsPhaseRead + cLTBitsPhase2)
  84. #define    cLTReadPhase3        (cLTBitsPhaseRead + cLTBitsPhase3)
  85. #define    cLTReadPhase4        (cLTBitsPhaseRead + cLTBitsPhase4)
  86. #define    cLTReadPhase5        (cLTBitsPhaseRead + cLTBitsPhase5)
  87. #define    cLTReadPhaseError    (cLTBitsPhaseRead + cLTBitsPhaseError)
  88.  
  89. #define    cLTWritePhase1        (cLTBitsPhaseWrite + cLTBitsPhase1)
  90. #define    cLTWritePhase2        (cLTBitsPhaseWrite + cLTBitsPhase2)
  91. #define    cLTWritePhase3        (cLTBitsPhaseWrite + cLTBitsPhase3)
  92. #define    cLTWritePhase4        (cLTBitsPhaseWrite + cLTBitsPhase4)
  93. #define    cLTWritePhase5        (cLTBitsPhaseWrite + cLTBitsPhase5)
  94. #define    cLTWritePhaseError    (cLTBitsPhaseWrite + cLTBitsPhaseError)
  95.  
  96. //----------------------------------------
  97. //    MISCELLANEOUS
  98. //----------------------------------------
  99. #define    cLTCheckAsyncErrors    TRUE                        // TRUE checks error return value of async calls to CM/Read/Write/Listen/Open/Close
  100.                                                         // This was needed to work around a bug in the Apple Modem Tool 1.5.1 which returns a
  101.                                                         // completely erroneous -1 error on each asynchronous call to CMRead.
  102.  
  103. //===========================================================================================
  104.  
  105. typedef    struct {
  106.             long    fMaxElements;                        // Maximum elements that the queue can contain (size of fData array)
  107.             long    fNumElements;                        // Number of elements currently in the queue
  108.             long    fHead;                                // Array index of first element
  109.             long    fTail;                                // Array index of last element
  110.             Handle    fData[];
  111.         } LTQueueRec, *LTQueuePtr, **LTQueueHdl;
  112.  
  113.  
  114. typedef    struct {                                        // A status record returned by LTGetSocketStatus describing a connection's current state
  115.             CMErr            fCMErr;                        // Error returned by CTB status routine CMStatus - noErr = good status record
  116.             CMStatFlags        fCMStatusFlags;                // Actual CTB status flags - never know when you might need them…
  117.             CMBufferSizes    fCMBufferSizes;                // Array of CTB buffer sizes - see definition of CMBufferSizes for more info…
  118.  
  119.             Boolean            fIsOpening;                    // TRUE if the connection is in the process of opening
  120.             Boolean            fIsOpen;                    // TRUE if the connection is currently open
  121.             Boolean            fIsClosing;                    // TRUE if the connection is in the process of closing
  122.             Boolean            fIsClosed;                    // TRUE if the connection is currently closed
  123.  
  124.             Boolean            fIsDataInAvail;                // TRUE if there is unread data available
  125.             Boolean            fIsDataOutAvail;            // TRUE if there is unwritten data available
  126.  
  127.             Boolean            fIsDataReadPending;            // TRUE if there is an asynchronous read pending on the DATA channel
  128.             Boolean            fIsDataWritePending;        // TRUE if there is an asynchronous write pending on the DATA channel
  129.  
  130.             Boolean            fIsBreakPending;            // TRUE if there is a break pending (on any channel)
  131.             Boolean            fIsListenPending;            // TRUE if there is a listen pending (on any channel)
  132.             Boolean            fIsIncoming;                // TRUE if there is an incoming request to connect (valid only when listening)
  133.         } LTSocketStatusRec;
  134.  
  135. //----------------------------------------
  136. //    NOTE:    Be sure to recompile the completion
  137. //            procedures if you modify
  138. //            LTSocketRec or LTGlobals!!!
  139. //----------------------------------------
  140. typedef    struct {
  141.             short        fPhase;                            // Used by LTIdle state machines
  142.  
  143.             long        fError;
  144.             ConnHandle    fConnHdl;                        // Handle to the Comm Toolbox Connection Record for this connection, or NIL if not being used
  145.             Handle        fAddressConfigHdl;
  146.  
  147.             short        fListenPhase;
  148.             short        fOpenPhase;
  149.             short        fClosePhase;
  150.  
  151.             short        fReadPhase;
  152.             short        fReadType;
  153.             long        fReadHeader;
  154.             long        fReadCount;
  155.             Handle        fReadBuffer;
  156.             LTQueueHdl    fReadQueue;
  157.  
  158.             short        fWritePhase;
  159.             short        fWriteType;
  160.             long        fWriteHeader;
  161.             long        fWriteCount;
  162.             Handle        fWriteBuffer;
  163.             LTQueueHdl    fWriteQueue;
  164.         } LTSocketRec;
  165.  
  166.  
  167. typedef struct {                                        // NOTE:  LTGlobals is a variable sized structure.
  168.             Handle        fCompProcResHdl_Listen;
  169.             Handle        fCompProcResHdl_Open;
  170.             Handle        fCompProcResHdl_Close;
  171.             Handle        fCompProcResHdl_Read;
  172.             Handle        fCompProcResHdl_Write;
  173.  
  174.             short        fNumSockets;
  175.             LTSocketRec    fSockets[];                        // NOTE:  fSockets[0] is RESERVED for future use!
  176.         } LTGlobals, *LTGlobalsPtr, **LTGlobalsHdl;
  177.  
  178. //----------------------------------------
  179.  
  180. pascal    LTQueueHdl    LTNewQueue (long maxElements);
  181. pascal    void        LTDisposeQueue (LTQueueHdl *LTQueueHdl);
  182. pascal    void         LTFlushQueue (LTQueueHdl q);
  183.  
  184. pascal    void         LTEnQueue (LTQueueHdl q, void *data);
  185. pascal    Handle         LTDeQueue (LTQueueHdl q);
  186.  
  187. pascal    long         LTGetQueueSize (LTQueueHdl q);
  188. pascal    long         LTGetMaxQueueSize (LTQueueHdl q);
  189.  
  190. //----------------------------------------
  191.  
  192. pascal    OSErr         LTOpenLlamaTalk (short    maxSockets, LTGlobalsHdl *globals);
  193. pascal    void         LTCloseLlamaTalk (LTGlobalsHdl globals);
  194.  
  195. pascal    void         LTIdle (LTGlobalsHdl globals);
  196.  
  197. pascal    OSErr         LTNewSocket (LTGlobalsHdl globals, Str255 toolName, Handle socketConfigHdl, Handle addressConfigHdl, short maxReadQueue, short maxWriteQueue, short *socket);
  198. pascal    void         LTDisposeSocket (LTGlobalsHdl globals, short socket);
  199.  
  200. pascal    Boolean     LTIsValidSocket (LTGlobalsHdl globals, short socket);
  201. pascal    long         LTGetSocketState (LTGlobalsHdl globals, short socket);
  202. pascal    void         LTGetSocketStatus (LTGlobalsHdl globals, short socket, LTSocketStatusRec *status );
  203.  
  204. pascal    void         LTListen (LTGlobalsHdl globals, short socket);
  205. pascal    void         LTOpen (LTGlobalsHdl globals, short socket);
  206. pascal    void         LTClose (LTGlobalsHdl globals, short socket);
  207. pascal    Handle         LTRead (LTGlobalsHdl globals, short socket);
  208. pascal    void         LTWrite (LTGlobalsHdl globals, short socket, Handle *data);
  209.  
  210. pascal    Boolean     LTChoose (Str255 *toolName, Handle *configHdl);
  211.  
  212. //===========================================================================================
  213.  
  214. #endif
  215.